<template>
  <view class="cart-box">
  <view class="cart" v-if="cart.length">
    <my-address></my-address>
    <view class="cart-title">
      <uni-icons class="cart-title-icon" type="shop" size="20"></uni-icons>
      <text>购物车</text>
    </view>
    <view class="cart-conster">
      <uni-swipe-action>
        <block v-for="(item,index) in cart" :key="index">
          <uni-swipe-action-item @click="removeGood(item)" :right-options="options">
            <my-goods :showNum="true" @changNum="changeNum" @radioChange="radioChange" :showRadio="true" :item="item">
            </my-goods>
          </uni-swipe-action-item>
        </block>
      </uni-swipe-action>
    </view>
    <view class="total">
    <my-total></my-total>
    </view>
  </view>
  <view class="none-goods" v-else>
    <image class="image" src="../../static/cart_empty@2x.png" mode=""></image>
    空空如也~
  </view>
   </view>
</template>

<script>
  import mixins from '../../mixins/mixins.js'
  import {
    mapState,
    mapMutations,
    mapGetters
  } from 'vuex'
  export default {
    mixins: [mixins],
    computed: {
      ...mapState('cart', ['cart']),
      ...mapGetters('cart',['changeInfo'])
    },
    watch:{
      changeInfo: function () {
       uni.setTabBarBadge({
         index:2,
         text:this.changeInfo + ''
       }) 
      }
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      };
    },
    methods: {
      ...mapMutations('cart', ['changeStatus', 'changCount','removeGoods']),
      removeGood(item){
        this.removeGoods(item.goods_id)
      },
      changeNum(e) {
        this.changCount(e)
      },
      radioChange(e) {
        this.changeStatus(e)
      }
    }
  }
</script>

<style lang="scss">
  .cart {
    padding-bottom: 160rpx;
    &-title {
      display: flex;
      align-items: center;
      padding-left: 15rpx;
      height: 80rpx;
      border-bottom: 1px solid #ccc;

      &-icon {
        margin-bottom: -7rpx;
        margin-right: 15rpx;
      }
    }
  }
  .none-goods{
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 14px;
    color: #999;
    padding-top: 300rpx;
    .image{
      height: 180rpx;
      width: 180rpx;
      margin-bottom: 40rpx;
    }
  }
</style>
